export default {
    data() {
        return {}
    },
    mounted() {
    },
    computed: {
        _userInfo() {
            return this.$store.getters.getUserInfo
        },
        _systemConfig() {
            return this.$store.getters.getSystemConfig
        }
    },
    methods: {
        /**
         * 保存用户信息
         * @param userInfo
         */
        setUserInfo(userInfo) {
            if (userInfo.token) sessionStorage.token = userInfo.token
            this.$store.commit("setUserInfo", Object.assign(userInfo, {}));
        },

        // /**
        //  * 查询系统配置信息
        //  */
        // getSystemConfig() {
        //     let self = this
        //     self.$api.getSystemConfig().then(res => {
        //         self.$store.commit("setSystemConfig", res.config);
        //     })
        // },
        /**
         * 查询系统初始化数据
         */
        getInitData() {
            let self = this
            return new Promise((resolve, reject) => {
                if (!sessionStorage.token) resolve()
                self.$api.getInitData().then(res => {
                    self.initRouterUrl(res.routerList)
                    self.$store.commit("setMenuData", res.menuList);
                    self.$store.commit("setApiData", res.apiList);
                    self.$store.commit("setRouterData", res.routerList);
                    resolve()
                }).catch(() => {
                    reject()
                })
            })
        },

        /**
         * 退出系统
         */
        logout() {
            let self = this;
            this.$confirm('确定退出系统吗？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                self.$api.logout({ token: sessionStorage.token });
                self.$router.push({ path: "/login" });
                setTimeout(() => {
                    self.clearSession()
                }, 1000)
            })
        },

        /**
         * 退出时清除信息
         */
        clearSession(){
            this.$store.commit("clearRefreshTime");
            this.$store.commit("setUserInfo", null);
            this.$store.commit('clearPage');
        }
    }
}
